<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>nginx</title>
</head>
<body>
    <button id="button">nginx 解决跨域</button>
    <script>
        const button = document.querySelector("#button");
        button.addEventListener('click', function() {
            const xhr = new XMLHttpRequest();
            xhr.responseType = 'json';
            xhr.open('GET', 'http://localhost/test.json', true);
            xhr.addEventListener('readystatechange', function() {
                if(this.readyState === 4) {
                    if((this.status >= 200 && this.status < 300) || this.status === 302) {
                        console.log("结果::", xhr.response);
                    }
                }
            }, false);
            xhr.send();
        }, false);
    </script>
</body>
</html>